package com.andy.mongo;

import me.prettyprint.cassandra.serializers.StringSerializer;
import me.prettyprint.hector.api.Cluster;
import me.prettyprint.hector.api.Keyspace;
import me.prettyprint.hector.api.beans.OrderedRows;
import me.prettyprint.hector.api.beans.Row;
import me.prettyprint.hector.api.factory.HFactory;
import me.prettyprint.hector.api.query.QueryResult;
import me.prettyprint.hector.api.query.RangeSlicesQuery;

import java.util.Iterator;

/**
 * Created with IntelliJ IDEA.
 * User: noah
 * Date: 8/6/12
 * Time: 5:25 PM
 * To change this template use File | Settings | File Templates.
 */
public class TestClient2 {

    public static void main(String[] args) {

        Cluster cluster = HFactory.getOrCreateCluster("Test Cluster", "192.168.100.49:9160");
        Keyspace keyspace = HFactory.createKeyspace("NOAH", cluster);

        RangeSlicesQuery<String, String, String> rangeSlicesQuery = HFactory
                .createRangeSlicesQuery(keyspace, StringSerializer.get(), StringSerializer.get(), StringSerializer.get())
                .setColumnFamily("Users")
                .setRange(null, null, false, 10);

        rangeSlicesQuery.setKeys(null, null);

        QueryResult<OrderedRows<String, String, String>> result = rangeSlicesQuery.execute();
        OrderedRows<String, String, String> rows = result.get();
        Iterator<Row<String, String, String>> rowsIterator = rows.iterator();

        while (rowsIterator.hasNext()) {
            Row<String, String, String> row = rowsIterator.next();

            if (row.getColumnSlice().getColumns().isEmpty()) {
                continue;
            }else{
            	System.out.println(row.getKey());
            	System.out.println(row.getColumnSlice());
            	System.out.println(row.getColumnSlice().getColumnByName("name").getValue());
            }

            System.out.println(row);
        }


    }

}
